package com.github.byakkili.bim.protocol.protobuf.ws;

import com.github.byakkili.bim.core.handler.command.CommandHandler;
import com.github.byakkili.bim.core.protocol.BaseWsProtocol;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @author Guannian Li
 */
public class WsProtoBufProtocol extends BaseWsProtocol {
    @Override
    public String name() {
        return "WS-ProtoBuf";
    }

    @Override
    public void addPipeline(Channel ch) {
        ch.pipeline()
                .addLast(new HttpServerCodec())
                .addLast(new ChunkedWriteHandler())
                .addLast(new HttpObjectAggregator(1024))
                .addLast(new WebSocketServerProtocolHandler("/ws", true))
                .addLast(WsProtoBufCodec.INSTANCE)
                .addLast(CommandHandler.INSTANCE);
    }
}
